<?php
/**
 * @package scuttle
 * @file /admin/actions/TagsDeleteAction.class.php
 **/

if (!defined('XOOPS_ROOT_PATH')) exit();

require_once XOOPS_MODULE_PATH. '/scuttle/class/AbstractDeleteAction.class.php';
require_once XOOPS_MODULE_PATH. '/scuttle/admin/forms/TagsAdminDeleteForm.class.php';
require_once XOOPS_MODULE_PATH. '/scuttle/admin/include/functions.php';


class Scuttle_TagsDeleteAction extends Scuttle_AbstractDeleteAction
{
	var $mObject = null;

	var $breadCrumbs     = array();
	var $confirmMssage   = null;
	var $moduleHeader    = null;
	var $menuDescription = null;

	function _getTag()
	{
		return xoops_getrequest('tag');
	}

	function &_getHandler()
	{
		$handler =& xoops_getmodulehandler('tags');
		return $handler;
	}

	function _setupActionForm()
	{
		$this->mActionForm =& new Scuttle_TagsAdminDeleteForm();
		$this->mActionForm->prepare();
	}

	function prepare(&$controller, &$xoopsUser, $moduleConfig)
	{
		$this->_setupActionForm();

		$handler =$this->_getHandler();
		$getTag = $this->_getTag();
		$mCriteria =& new CriteriaCompo();
		$mCriteria->add(new Criteria('tag', $getTag));
		$this->totalCount = $handler->getCount($mCriteria);
	}

	function _doExecute()
	{
		$handler =$this->_getHandler();

		if (!$handler->deleteTag($this->_getTag())) {
			return SC_FRAME_VIEW_ERROR;
		}

		return SC_FRAME_VIEW_SUCCESS;
	}


	function getDefaultView(&$controller, &$xoopsUser)
	{
		if ($this->totalCount == 0 ) {
			return SC_FRAME_VIEW_ERROR;
		}

		$this->breadCrumbs[] = array('name' => _AD_SC_TAGS ,'url'  => 'index.php?action=TagsList' ) ;
		$this->breadCrumbs[] = array('name' => _AD_SC_TAGS_DELETE) ;
		$this->confirmMssage   = sprintf(_AD_SC_TAGS_DELETE_CONFIRM,$this->_getTag(),$this->totalCount) ;

		return SC_FRAME_VIEW_INPUT;
	}


	function executeViewInput(&$controller, &$xoopsUser, &$render)
	{
		global $adminmenu;

		$render->setTemplateName('scuttle_tags_delete.html');
		$render->setAttribute('module_info'   , getModuleInfo());
		$render->setAttribute('module_header' , $this->moduleHeader);
		$render->setAttribute('bread_crumbs'  , $this->breadCrumbs);
		$render->setAttribute('set_menu'      , $adminmenu );
		$render->setAttribute('set_menu_no'   , 3);
		$render->setAttribute('set_menu_desc' , $this->menuDescription);
		$render->setAttribute('confirm_mssage', $this->confirmMssage);

		$render->setAttribute('actionForm'    , $this->mActionForm);

		$render->setAttribute('tag', $this->_getTag());
		$render->setAttribute('total_count', $this->totalCount);


	}

	function execute(&$controller, &$xoopsUser)
	{
		if ($this->totalCount == 0 ) {
			return SC_FRAME_VIEW_ERROR;
		}

		if (xoops_getrequest('_form_control_cancel') != null) {
			return SC_FRAME_VIEW_CANCEL;
		}

		return $this->_doExecute() ? SC_FRAME_VIEW_SUCCESS : SC_FRAME_VIEW_ERROR;
	}



	function executeViewSuccess(&$controller, &$xoopsUser, &$render)
	{
		$controller->executeRedirect('index.php?action=TagsList', 1, _AD_SC_TAGS_DELETE_SUCCESS);
	}
	function executeViewError(&$controller, &$xoopsUser, &$render)
	{
		$controller->executeRedirect('index.php?action=TagsList', 1, _AD_SC_TAGS_DELETE_ERROR);
	}
	function executeViewCancel(&$controller, &$xoopsUser, &$render)
	{
		$controller->executeForward('index.php?action=TagsList');
	}
}

?>